package com.ruoyi.web.controller.chargeback.controller;


import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.charge.vo.MerchantVo;
import com.ruoyi.charge.bo.MerchantQueryBo;
import com.ruoyi.charge.bo.MerchantAddBo;
import com.ruoyi.charge.bo.MerchantEditBo;
import com.ruoyi.charge.service.IMerchantService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 支付配置Controller
 *
 * @author fanqie
 * @date 2021-10-28
 */
@Api(value = "支付配置控制器", tags = {"后台支付配置管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/back/merchant")
public class BackMerchantController extends BaseController {

    private final IMerchantService iMerchantService;

    /**
     * 查询支付配置列表
     */
    @ApiOperation("查询支付配置列表")
    @PreAuthorize("@ss.hasPermi('back:merchant:list')")
    @GetMapping("/list")
    public TableDataInfo<MerchantVo> list(MerchantQueryBo bo) {
        startPage();
        List<MerchantVo> list = iMerchantService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出支付配置列表
     */
    @ApiOperation("导出支付配置列表")
    @PreAuthorize("@ss.hasPermi('back:merchant:export')")
    @Log(title = "支付配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MerchantVo> export(MerchantQueryBo bo) {
        List<MerchantVo> list = iMerchantService.queryList(bo);
        ExcelUtil<MerchantVo> util = new ExcelUtil<MerchantVo>(MerchantVo.class);
        return util.exportExcel(list, "支付配置");
    }

    /**
     * 获取支付配置详细信息
     */
    @ApiOperation("获取支付配置详细信息")
    @PreAuthorize("@ss.hasPermi('back:merchant:query')")
    @GetMapping("/{id}")
    public AjaxResult<MerchantVo> getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(iMerchantService.queryById(id));
    }

    /**
     * 新增支付配置
     */
    @ApiOperation("新增支付配置")
    @PreAuthorize("@ss.hasPermi('back:merchant:add')")
    @Log(title = "支付配置", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody MerchantAddBo bo) {
        return toAjax(iMerchantService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改支付配置
     */
    @ApiOperation("修改支付配置")
    @PreAuthorize("@ss.hasPermi('back:merchant:edit')")
    @Log(title = "支付配置", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody MerchantEditBo bo) {
        return toAjax(iMerchantService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除支付配置
     */
    @ApiOperation("删除支付配置")
    @PreAuthorize("@ss.hasPermi('back:merchant:remove')")
    @Log(title = "支付配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iMerchantService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
